package quickstart;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

import java.io.UnsupportedEncodingException;

/**
 * @author ：zhz
 * @date ：Created in 2021/02/09
 * @version: V1.0
 * @slogan: 天下风云出我辈，一入代码岁月催
 * @description: 生产者
 **/
public class Producer {
    public static void main(String[] args) throws MQClientException, InterruptedException {
        DefaultMQProducer producer = new DefaultMQProducer("please_rename_unique_group_name");
        producer.setNamesrvAddr("localhost:9876");
        producer.start();
        for (int i = 0; i < 2; i++) {
            try {
                Message message = new Message("TopicTest",
                        "TagA",
                        ("Hello RocketMQ" + i).getBytes(RemotingHelper.DEFAULT_CHARSET)
                );
                message.setDelayTimeLevel(3);
                SendResult sendResult=producer.send(message);
                System.out.println(sendResult);
            } catch (Exception e) {
                e.printStackTrace();
                Thread.sleep(1000);
            }
        }
        producer.shutdown();
    }

}
